Skip to content

Improve CLI Argument Parsing to Handle Space Separated Values#581

Closed
Alstruit wants to merge 1 commit into
SteamRE:masterfrom
Alstruit:fix_multiple_args
Closed

Improve CLI Argument Parsing to Handle Space Separated Values#581
Alstruit wants to merge 1 commit into
SteamRE:masterfrom
Alstruit:fix_multiple_args

Conversation

@Alstruit

@Alstruit Alstruit commented Dec 27, 2024

Copy link
Copy Markdown

The original implementation assumed each argument would contain at most one value, which could cause exceptions when attempting to parse multiple values (e.g., -depot "11 12 13") into numeric types.

  • The code also checks if the TypeConverter for the given type T is available and logs a warning if it’s not, preventing potential null-reference issues.

  • It stops parsing values once it encounters a new parameter which is consistent with typical CLI usage patterns.

System.ArgumentException occurs when handling space-separated arguments provided as a single string. GetParameterList<T>() function attempts to parse the string of numbers as a UInt32.
var strParam = args[index];

// Handle the scenario where we have a single space-separated string of values
if (strParam.Contains(" ") && !strParam.StartsWith("-"))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If args is already split by space, how would this ever hit?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for in case if the arg is enclosed with quotes. Especially if -dir contains spaces.

@xPaw

xPaw commented Dec 29, 2024

Copy link
Copy Markdown
Member

To be honest I would prefer #234 rather than trying to hack in support for this in the current system, but System.CommandLine was kind of abandoned...

I've had success using https://github.com/Cysharp/ConsoleAppFramework

@Alstruit

Alstruit commented Dec 29, 2024

Copy link
Copy Markdown
Author

I agree that this appears to be hacky. To be fair this only happens if one of the arguments is enclosed with quotes.
Im reopening in case if there any interests.

@Alstruit Alstruit closed this Dec 29, 2024
@Alstruit Alstruit reopened this Jan 9, 2025
@Alstruit Alstruit closed this by deleting the head repository Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants